﻿
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System;

using System.Data.SqlClient;
using System.Web.Services;

using System.Data;
using System.Configuration;
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Data.SqlClient;
using System.Drawing;
using System.Net.Mail;

using System.Web.Services;

public partial class admin_view_sell : System.Web.UI.Page
{
    string ss;
   
    protected void Page_Load(object sender, EventArgs e)
    {

        if (Session["email"] == null)
        {
            Response.Redirect("sessiont.aspx");
        }
        ss = Session["p_id"].ToString();
        Label1.Text = Session["email"].ToString();

        if (Page.IsPostBack)
        {
        }
        else
        {
            string str = Session["p_id"].ToString();
           // Image1.ImageUrl = "property1.ashx?p_id=" + str.ToString();
            SqlConnection conn = null;
            conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);


            conn.Open();
            SqlCommand scmd = new SqlCommand("SELECT * FROM properties where p_id='" + Session["p_id"] + "'", conn);

            SqlDataReader dr = scmd.ExecuteReader();
            if (dr.Read())
            {

                txtfname1.Text = dr[7].ToString();
                lblstreet.Text = dr[13].ToString();
                lblprice.Text = dr[94].ToString();
                Label2.Text = dr[95].ToString();
                lblproptype.Text = dr[5].ToString();
                lblcond.Text = dr[31].ToString();
                lblelevatr.Text = dr[88].ToString();
                lblparking.Text = dr[40].ToString();
                lbshower.Text = dr[54].ToString();
                lbltoilet.Text = dr[48].ToString();
                lblac.Text = dr[52].ToString();

                Label3.Text = dr[8].ToString();
                lblcity.Text = dr[12].ToString();
            Lblda.Text = dr[114].ToString();
                lbltype.Text = "To Sell";
            }


            dr.Close();
        }
    ListImages();
    
}

    private void ListImages()
    {
        DirectoryInfo dir = new DirectoryInfo(Server.MapPath("upload/" + Session["p_id"] + "/image"));
        FileInfo[] file = dir.GetFiles();
        ArrayList list = new ArrayList();
        foreach (FileInfo info in file)
        {
            if (info.Extension == ".jpg" || info.Extension == ".jpeg" || info.Extension == ".gif" || info.Extension == ".png")
            {
                list.Add(info);
            }


            FileRepeater.DataSource = list;
            FileRepeater.DataBind();
        }
    }


    //protected void btnNewEntry_Click(object sender, EventArgs e)
    //{
    //    Page.ClientScript.RegisterStartupScript(
    //    this.GetType(), "OpenWindow", "window.open('print_sell.aspx','_newtab');", true);
    //}
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {

        if (e.CommandName == "edit")
        {

            //Label1.Text = "hello";
            int index = Convert.ToSByte(e.CommandArgument);

            GridViewRow row = GridView1.Rows[index];
            SqlDataAdapter adp = new SqlDataAdapter();
            SqlCommand cmd1 = new SqlCommand();
            DataSet ds = new DataSet();


            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Connstr"].ConnectionString);

            con.Open();

            SqlCommand objectvalue = new SqlCommand("", con);
            cmd1.Connection = con;



            SqlCommand dmc = new SqlCommand("select p_id from property_buy where p_id='" + row.Cells[0].Text + "'", con);

            dmc.ExecuteNonQuery();
            Session["p_id"] = row.Cells[0].Text;

            con.Close();
            // Response.Write(Session["p_id"]);
            // Response.Write(@"<script language='javascript'>alert('clent has been selected')</script>");

            Response.Redirect("view_buy.aspx");
            // con.Close();


        }

        if (e.CommandName =="view")
        {

            //Label1.Text = "hello";
            int index = Convert.ToSByte(e.CommandArgument);

            GridViewRow row = GridView1.Rows[index];
            SqlDataAdapter adp = new SqlDataAdapter();
            SqlCommand cmd1 = new SqlCommand();
            DataSet ds = new DataSet();


            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Connstr"].ConnectionString);

            con.Open();

            SqlCommand objectvalue = new SqlCommand("", con);
            cmd1.Connection = con;



            SqlCommand dmc = new SqlCommand("select p_id from property_buy where p_id='" + row.Cells[0].Text + "'", con);

            dmc.ExecuteNonQuery();
            Session["p_id"] = row.Cells[0].Text;

            con.Close();
            // Response.Write(Session["p_id"]);
            // Response.Write(@"<script language='javascript'>alert('clent has been selected')</script>");

            Response.Redirect("view_buy.aspx");
            // con.Close();


        }

    }
    protected void Save_Click(object sender, EventArgs e)
    {

    }
    protected void SearchButton_Click(object sender, EventArgs e)
    {


        //  string pageurl="Default.aspx?Id=6&RollNo=15";

        //Response.Write(<script> window.open( ‘"+pageurl+"’,'_blank' ); </script>);
        //Response.End();
    }

    protected void LinkButton1_Click(object sender, System.EventArgs e)
    {
        Session.Abandon();
        Response.Redirect("../admin.aspx");
    }
}